package main

import (
	"MxShop/initter"
	_ "MxShop/initter"
	"MxShop/middware"
	"fmt"
	_ "github.com/dgrijalva/jwt-go"
	"github.com/hashicorp/consul/api"
	"go.uber.org/zap"
	"log"
)

func GetALl() {
	config := api.DefaultConfig()
	config.Address = "127.0.0.1:8500"
	client, _ := api.NewClient(config)
	result, _ := client.Agent().Services()
	zap.S().Info("获取搜有服务列表", result)
}

func FilterService() {
	config := api.DefaultConfig()
	config.Address = "127.0.0.1:8500"
	client, _ := api.NewClient(config)
	result, _ := client.Agent().ServicesWithFilter(`Service == "userWeb"`)
	fmt.Println(result)
}

func main() {
	//路由
	router := initter.InitRouter()
	//动态生成端口号  安全性
	port, err := middware.GetAddr()
	if err != nil {
		log.Printf("端口生成失败")
	}
	port = 6630
	zap.S().Infow("项目启动", zap.String("IP:::", "0.0.0.0"), zap.Int("端口:::", port))
	//Api端已成功启用，IP为xxxxx 端口号为xxxx
	err = router.Run(fmt.Sprintf(":%d", port)) // 监听并在 0.0.0.0:8080 上启动服务
	if err != nil {
		zap.S().Panic(err.Error())
	}
}
